<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.*"%>
<%@ page import="com.hz.util.*" %>
<%@ page import="com.hz.model.Hobby" %>
<%@ page import="com.hz.control.HobbyControl" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>project</title>

		<title>project</title>
		<link rel="stylesheet" type="text/css" href="../../../css/active.css"/>
		<script type="text/javascript" src="../../common/js/jquery.js"></script>
		<script type="text/javascript">
	$(document).ready(function() {
		$('#formdiv').hide();
		$('[name=form_upload]').hide();
		$('#update_project').hide();
		$('#upload_btn').click(function() {
		$('[name=form_upload]').slideToggle();
				});
		$('#add_project').click(function() {
			$('#formdiv').slideToggle();
		});
		$('[name=edit]').click(function() {
		    $('#update_projectid').val($(this).prev().val());
		    $('#update_projectname').val($(this).parent().prev().text());
			$('#update_project').fadeIn();
		});
		$('#cancel').click(function() {
			$('#update_project').fadeOut();
		})
			$('#submit_btn').click(function() {
			$.ajax( {
				type : "get",
				cache : false,
				url : "addHobby.jsp",
				dataType : "json",
				data : {
					projectname : $('#new_projectname').val()
				},
				success : function(data) {
					if (data.status == 1) {
						window.location.reload();
					} else {
						alert("插入失败！");
					}
				}
			});
		})
		$('#update_btn').click(function() {
			$.ajax( {
				type : "get",
				cache : false,
				url : "updateHobby.jsp",
				dataType : "json",
				data : {
					projectname : $('#update_projectname').val(),
					projectid : $('#update_projectid').val()
				},
				success : function(data) {
					if (data.status == 1) {
						window.location.reload();
					} else {
						alert("修改失败！");
					}
				}
			});
		})
				$('[name=delete]').click(function() {
					var isConfirm = confirm("确认删除？");
					if (isConfirm == true) {
						$.ajax( {
							type : "get",
							cache : false,
							url : "deleteHobby.jsp",
							dataType : "json",
							data : {
								projectid : $(this).prev().prev().val()
							},
							success : function(data) {
								if (data.status == 1) {
									window.location.reload();
								} else {
									alert("删除失败！");
						}
					}
				});
			}
		})
	
	})
</script>
</head>
<body>
<form>

<table  class='add' >
<tbody>
<%
	request.setCharacterEncoding("UTF-8");
	int pages = ParamUtil.getInt(request, "pages", 0);
	int rowsPerPage = ParamUtil.getInt(request, "pageSize", 10);
	Hobby project = new Hobby();

	List<Hobby> list = new ArrayList<Hobby>();
	list = (List) HobbyControl.getAllHobbies();
	      
	for (int i = 0; i < list.size(); i++) {
		project = list.get(i);
%>  
	
		<tr>
		<td><%=project.getHobbyName()%></td>
		<td>
								<input type="hidden" value="<%=project.getId()%>">
								<input type="button" value="编辑" name="edit" class="inputButton2">
								<input type="button" value="删除" name="delete" class="inputButton2">
							</td>
		</tr>
	<%
		}
	%>   	
   	</tbody>
   </table>
   <div class='add1'>
   <input type="button" id="add_project" value="添加服务类型" class="inputButton3"/></div>	
			</form>
			
		<div id="formdiv" class='add1'>
			<form action="#" method="post">
			志愿者服务类型：
			<input type="text" id="new_projectname" name="new_projectname" value="" />
			<input type="button" id="submit_btn" value="提交" class="inputSearch" />
			</form>
		</div>
		
			<div id="update_project">
			<table class='add'>
				<tr>
				<td>志愿者服务类型：</td>
				<td><input type="text" id="update_projectname" /><input type="hidden" id="update_projectid" /></td>
				</tr>
				<tr><td><input type="button" id="update_btn" value="修改" /></td>　
				<td><input type="button" id="cancel" value="取消"></td></tr>
				</table>
			</div>
</body>
</html>